Microsoft Visual Basic Express Starter Kit
Starter Kit: My Movie Collection
Contents:
Introduction
Download the Updated Web Plus
Edition
Getting Started
How My Movie Collection Works
My Movie Collection Starter Kit In-Depth
Introduction

The My Movie Collection starter kit is a sample application designed to help you track your collection of movies. With this kit, you can organize movies in your collection, rate them, and look up information about them. Plus, you can change the application anyway you want and see the source code.
Download
the Updated Web Plus Edition
Want to connect your movie collection to the Web and download information about your movies? The Web Plus edition of the My Movie collection starter kit does just that: it tracks your collection and searches for movies using an online Web service. The Web Plus edition also contains updates to the starter kit that aren't in the version shipped with Visual Basic Express Edition, so you will want to download it even if you don't want to use the Web features.
You can download the Web Plus edition for free from here.
Getting Started
The first step to getting your movie collection application up and running is loading the starter kit project by choosing the My Movie Collection Starter Kit template in the New Project dialog box.
1) Starting the My Movie Collection Application
To see the application in action, you need to run it.
To run the application
- Press F5 to run the application.
The form for the application is displayed. This is the form where you’ll enter information about your movies, organize them, and search through your collection.
2) Adding Movies to your Collection
Let's add a movie from your collection.
To add a movie to your collection
- On the form, click Add Title.
A new entry, called a record, opens in the list above the Add Title button.
- In the dvd details boxes to the right, add the title of a favorite movie and other information, such as director or movie rating.
The database file that is part of your project is updated with the information automatically anytime you add, delete, or modify data.
At any time, you can select a movie from the grid and view its details.
3) Updating Information about your Collection
Updating a record is just as easy as entering one.
To update a record in your movie collection
- In the list, click the record you would like to update.
- The data from this record is displayed in the boxes to the right.
- Choose the data that you would like to update and make your change. Your new information is saved as soon as you move from a box.
4) Searching Online for Information about a Movie
If you have the Web Plus edition of the My Movie Collection starter kit, you can take advantage of the rich movie collection that is provided by Amazon.com Web service. The My Movie Collection starter kit application is already connected, and you can use this connection to download information about your favorite films. Don't forget: You need to be connected to the Internet for this to work, and you need the Web Plus edition, which can be downloaded for free here.
To get online information about a movie
- Connect to the Internet, if you are currently offline.
- On the form, click the Search Online button.
- In the first box, type a keyword or keywords related to the film, and then click the Search button. The keywords can be words from the title, actor names, or any other words having to do with the film. The first ten films that match are added to the results list; if the film that you were looking for is not included in the first ten, you can enter additional keywords to narrow the results.
- If there's a match with the film you were looking for, select it and click Add To Collection.
The movie is added to your collection.
5) Assigning a Rating to a Movie
Now you can be a movie critic. Movies that are added via the Web don't have ratings or comments, but you can add your own.
To assign a rating to a movie
- Using the mouse, click the number of stars to assign a rating (1 through 5). The stars turn yellow when selected. Your rating is automatically saved.
To add a comment for a movie
- Select the Comments field and enter your comments. The comments are automatically saved
6) Customizing the Application
Let's see how easy it is to customize the look and feel of the application. You can customize the text of labels and forms, and use your own images and icons for your application. Before you can do this, however, you need to stop the application from running.
To stop the application from running
- Switch to the Visual Basic Express Edition window.
- On the Debug menu, click Stop Debugging.
You’re in design mode. This mode is where you can make code and design changes.
Customizations
The My Movie Collection application consists of several forms. MainForm.vb is the starting point for the application. There are also two custom controls:
- ListDetails.vb – This control is where you view details about your collection. The information comes from the My Movie Collection database.
- SearchOnline.vb – This control is connected to the Amazon.com Web service, and is what you use to search online.
You can customize the text or images of the form or any of the controls by setting properties in the Properties window. Or, you can update properties by editing the code associated with the forms.
The following examples show a few of the ways you might want to customize the application.
To change the text displayed in the Title Bar
- In Solution Explorer, right-click MainForm.vb and choose View Designer.
- In the Properties window, make sure that MainForm is selected in the dropdown list, then locate and change the value of Text property. For example, change the text from "My Movie Collection" to "[Your Name] Movie Collection."
The Text property of the form is changed once you press ENTER. Notice that the Title Bar of the form reflects your new text.
You will probably also want to change the text displayed on the form itself to match, since it still reads "my movie collection".
To change the text displayed on the form
- In Solution Explorer, right-click MainForm.vb and choose View Designer.
- Select the Label control that contains the text "my movie collection".
- In the Properties window, locate and change the value of Text property. For example, change the text from "My Movie Collection" to "[Your Name] Movie Collection."
The Text property of the label is changed once you press ENTER.
You can change the properties of any of the custom controls that appear on the form.
Images for the application are managed in the Resources tab of the Project Designer.
To add a background image
- In Solution Explorer, double-click My Project. The Project Designer opens. This designer makes it easy to modify or add content such as resource files.
- On the left side, click the Resources tab.
- In the Categories list, select Images.
- Add your favorite images to the designer. Click the Add button and then click Existing File. Locate to the image you want to add. Or drag and drop an image file from Windows Explorer (for example, from My Pictures) to the designer.
-
In Solution Explorer, right-click ListDetails.vb and choose View Designer.
The ListDetails form will appear in the Form designer.
- Select the DVDDetailsPanel control (the dark gray box on the right side of the form).
In the Properties window, locate the BackgroundImage property and click the ellipsis button to the right of the property.
The Select Resource dialog box will open.
-
Select the image that you just added, and then click OK.
The new background image will appear in the designer. You can change the image to anything in the Resources folder, including the image you added.
Do you ever have movie titles too long to fit in your labels? This will fix it.
To change display behavior of ListDetails
- In Solution Explorer, right-click ListDetails.vb and choose View Designer.
- Click the Label2 control ("[Title]") , and in the Properties window set AutoSize property = False; set AutoEllipsis property = True.
To test your application
- Press F5 to rebuild the application. You can now see your changes.
Move your mouse over the title of the movie in your collection to show its ToolTip and ellipsis.
Want to add a new field to keep track of the actors in your movies? Here's how.
To add a field to ListDetails
- In Solution Explorer, right-click ListDetails.vb and choose View Designer.
- From the Toolbox window, drag a TextBox control onto the form beneath the Description field. Resize and rearrange the controls as necessary.
- With the TextBox control selected, choose the (DataBindings) property in the Properties window and expand it.
- Select the (Advanced) property and click the Ellipsis button to open the Formatting and Advanced Binding dialog box.
- From the Binding dropdown list, choose DVDsBindingSource - Actor, and then click Ok.
- From the Toolbox, drag a Label control onto the form and place it next to the new TextBox control.
- In the Properties window, change the Text property to "Actors".
When you run the application again you should see the Actors field. Enter the names of the actors for the movie.
Do you have movies in more than one format, for example DVD and VHS? Add a field to the database to track the media type.
To add a field to the database
- In Solution Explorer, right-click DVDCollectionDatabase.mdf and choose Open. The Database Explorer window will open.
- In the Database Explorer, expand the Tables node and select DVDs, and then right-click and choose Open Table Definition.
- In the Table designer, scroll to the bottom of the list and in the Column Name column type "Media".
- In the Data Type column, select nvarchar(MAX) from the dropdown list.
- On the File menu, choose Save DVDs to save your changes.
You can now add a Media field to the ListDetails view as you did with the Actors field in the previous example.
How My Movie Collection Works
This has been a brief introduction to the My Movie collection starter kit. You can use the application some more, and get more practice in customizing the look and feel. You might try rearranging the layout of the controls or dramatically altering the look and feel. If you are comfortable with Visual Basic code, dissect the functionality of the application by examining the source code. Finally, add features to the application to organize books and music, or write your own application based on this one.
My Movie Collection Files and Folders
The My Movie Collection starter kit consists of the following files and folders.
| MainForm.vb | Main form; serves as container for controls. |
| ListDetails.vb | Custom user control; serves as a viewer and editor for your movie collection. |
| SearchOnline.vb | Custom user control; serves as a search tool for online web services. |
| DVDCollectionDatabase.mdf | Database for movie collection. Note: When adding a database to your project, it is important to understand where the database is located. For more information, look for the help topic "How To: Manage Local Data Files in Your Project". |
| DVDCollectionDataSet.xsd | Dataset and data layer objects; helps to do database operations such as loading, saving, and validating data. |
| Resources folder | Folder containing images, such as bitmaps. |
| Documentation folder | Folder containing documentation and Help for the starter kit. Right-click Getting Started Tutorial.htm and then click View in Browser to view the documentation. |
| Controls folder | Custom controls used by the collection. |
| Web References folder | (Web Plus edition only) Folder containing Web Service connection. |
| Project folder | Folder containing Visual Basic project and application settings. Double-click to open the Project Designer. |
My Movie Collection Starter Kit
In-Depth
This section describes the workings of the My Movie Collection kit, and suggests entry points for your customizations.
Online search
(Web Plus edition only) The application is making an online search request for this
data, and it is responding back with XML describing the resulting data. This is
analogous to visiting the Web page and performing a search; the application programmatically
makes a request to the Web service, and the service responds back with XML data.
Notice that only a few lines of code are used to fill a list of DVD objects and bind them to the screen in the PerformSearch method of the SearchOnline.vb file.
'object responsible for containing dvd search results
Dim searchResults As New BindingList(Of DVD)
'simple wrapper object responsible for handling requests and responses from the Amazon.com Web service
Dim amazonService As New SimpleAmazonWS
'show hour glass during the search to tell users that work is being done
Me.Cursor = Cursors.WaitCursor
Try
'request search results from the Web service passing in the user's search criteria
searchResults = amazonService.SearchDVDs(Me.SearchTextBox.Text)
'data bind the search results to the form UI
Me.DVDBindingSource.DataSource = searchResults
Catch ex As Exception
MsgBox(String.Format("There was a problem connecting to the Web service. Please verify that you are connected to the Internet. Additional details: {0}", ex.Message))
My.Application.Log.WriteException(ex)
Finally
'set cursor back to the default now that work is done
Me.Cursor = Cursors.Default
End Try
'tell the user how many results were found. Use String.Format feature to concat strings in a Localization-friendly way
Me.Label2.Text = String.Format("{0} results found. ", searchResults.Count.ToString)
End Sub
This method creates a List of DVD objects, and then calls the simplified Amazon.com Web service to fetch DVD search results based on search criteria (specified by the SearchTextBox control on the user’s display). The SearchOnline control is then data bound to the list of DVD object results returned by the Web service. This is done by setting the control’s DataConnector.Datasource = [List of DVD objects].
Data binding
Visual Basic treats this data like a list of DVD objects and can bind (or base the data in) the controls to it. Visual Basic Express Edition permits you to bind user interface elements to several kinds of data:
- databases
- objects
- Web services
Creating elements bound to data is as easy as drag and drop, or using the smart tag on a particular control. You can then write additional code to rebind your element to data dynamically, so long as it's the same kind of data.
For example, from your online search for DVD titles, click the first, then second items in the results list. Notice that the grid has been populated with data from the web service.
Clicking on a particular item shows details in the boxes on the right side. The application also retrieves images from the image URL and displays them in the Picture Box, if there are any. This is done asynchronously.
Now, select your favorite item and click Add to Collection. The following code is executed.
'try to add data to the collection
Try
'check boundary cases where DVD list is empty or there is no current selection
If (Me.DVDBindingSource.Count > 0) AndAlso (Me.DVDBindingSource.Current IsNot Nothing) Then
'object that stores the current DVD selection
Dim currentDVD As DVD = CType(Me.DVDBindingSource.Current, DVD)
'try to cache the image to the dvd object
If Me.PictureBox1.Image IsNot Nothing Then
'try loading from picture box first
currentDVD.ImageCache = Me.PictureBox1.Image
ElseIf currentDVD.ImageUrl <> "" Then
'else try from the source URL
Me.PictureBox1.Load(currentDVD.ImageUrl)
currentDVD.ImageCache = Me.PictureBox1.Image
End If
'convert custom DVD object to the datable / datarow format used by the application, and
'add the datarow to the datatable
My.Forms.MainForm.ListDetailsPart.DVDCollectionDataSet.DVDs.AddDVDsRow(currentDVD)
'update display to show ListDetailsPart with new row selected
My.Forms.MainForm.ListDetailsPart.DVDsBindingSource.MoveLast()
My.Forms.MainForm.ShowListDetailsPart()
Else
MsgBox("No DVD is selected. Please select a DVD before adding to collection. ")
End If
Catch ex As Exception
MsgBox("There was a problem adding this DVD to the collection. ")
My.Application.Log.WriteException(ex)
End Try
End Sub
This step converts the list of DVD objects into the format used by the DVD collection, the DVDCollectionDataSet, and then adds a new DVDCollectionRow. This step is analogous to entering a DVD title into the collection by hand. You can see the code that does the conversion by viewing the DVDCollectionDataSet.vb file.
The application dynamically starts viewing the collection again. At this point you can refine the data in the editable fields. You can also provide personalized data like comments and a rating.
User controls
The My Rating field is implemented as a user control named RatingPicker.vb, created in Visual Basic. If you look at the form in design mode, you won't see the RatingPicker control - it's created when the form loads in the InitRatingPickerControl() method.
You may have noticed that when you move the mouse over the RatingPicker control that the stars "light up" as you pass over them. This is handled in the Star_MouseHover method with the following code:
If Not Me.m_Initializing Then
Select Case (hoverOverStar.Name)
Case Me.Star1.Name
Me.PreviewNewRating(RatingPickerValue.Poor)
Case Me.Star2.Name
Me.PreviewNewRating(RatingPickerValue.BelowAverage)
Case Me.Star3.Name
Me.PreviewNewRating(RatingPickerValue.Average)
Case Me.Star4.Name
Me.PreviewNewRating(RatingPickerValue.AboveAverage)
Case Me.Star5.Name
Me.PreviewNewRating(RatingPickerValue.Excellent)
End Select
End If
The stars (Star1, Star2, etc.) are picture boxes contained in the user control. Depending on which star the mouse is over, the PreviewNewRating method is called with a RatingPickerValue. The following code sets the Image for each star based on the rating:
Dim setimage As Bitmap = My.Resources.star_filled
Select Case (newRating)
Case RatingPickerValue.NotSet
Me.Star1.Image = notsetimage
Me.Star2.Image = notsetimage
Me.Star3.Image = notsetimage
Me.Star4.Image = notsetimage
Me.Star5.Image = notsetimage
Case RatingPickerValue.Poor
Me.Star1.Image = setimage
Me.Star2.Image = notsetimage
Me.Star3.Image = notsetimage
Me.Star4.Image = notsetimage
Me.Star5.Image = notsetimage
Case RatingPickerValue.BelowAverage
Me.Star1.Image = setimage
Me.Star2.Image = setimage
Me.Star3.Image = notsetimage
Me.Star4.Image = notsetimage
Me.Star5.Image = notsetimage
Case RatingPickerValue.Average
Me.Star1.Image = setimage
Me.Star2.Image = setimage
Me.Star3.Image = setimage
Me.Star4.Image = notsetimage
Me.Star5.Image = notsetimage
Case RatingPickerValue.AboveAverage
Me.Star1.Image = setimage
Me.Star2.Image = setimage
Me.Star3.Image = setimage
Me.Star4.Image = setimage
Me.Star5.Image = notsetimage
Case RatingPickerValue.Excellent
Me.Star1.Image = setimage
Me.Star2.Image = setimage
Me.Star3.Image = setimage
Me.Star4.Image = setimage
Me.Star5.Image = setimage
Case Else
Me.Star1.Image = notsetimage
Me.Star2.Image = notsetimage
Me.Star3.Image = notsetimage
Me.Star4.Image = notsetimage
Me.Star5.Image = notsetimage
End Select
You could easily customize the control to use different images, or to display ratings on a scale of ten instead of five.
For more information
- Provide feedback on this documentation here.
- Other Visual Basic Starter Kits are available here.
- Get further details on Visual Basic Express Edition here.
© 2000 Microsoft Corporation and/or its suppliers. All rights reserved. Terms of Use.